package com.cl.it.custom.service.impl;

import com.cl.it.custom.model.CompanyVo;
import com.cl.it.custom.service.IBizCompanyService;
import com.cl.it.mbg.entity.Company;
import com.cl.it.mbg.entity.QccBusinessInfo;
import com.cl.it.mbg.entity.QccCompanyInfo;
import com.cl.it.mbg.entity.QccFinancingInfo;
import com.cl.it.mbg.service.ICompanyService;
import com.cl.it.mbg.service.IQccBusinessInfoService;
import com.cl.it.mbg.service.IQccCompanyInfoService;
import com.cl.it.mbg.service.IQccFinancingInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IBizCompanyServiceImpl implements IBizCompanyService {

    @Autowired
    private ICompanyService companyService;

    @Autowired
    private IQccBusinessInfoService qccBusinessInfoService;

    @Autowired
    private IQccCompanyInfoService qccCompanyInfoService;

    @Autowired
    private IQccFinancingInfoService qccFinancingInfoService;


    @Override
    public CompanyVo getCompanyInfo(String name) {
        QueryWrapper<Company> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        Company company = companyService.getBaseMapper().selectOne(queryWrapper);

        QueryWrapper<QccBusinessInfo> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("name", company.getName());
        List<QccBusinessInfo> qccBusinessInfos = qccBusinessInfoService.getBaseMapper().selectList(queryWrapper1);

        QueryWrapper<QccCompanyInfo> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("name", company.getName());
        QccCompanyInfo qccCompanyInfo = qccCompanyInfoService.getBaseMapper().selectOne(queryWrapper2);

        QueryWrapper<QccFinancingInfo> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("name", company.getName());
        queryWrapper3.orderByDesc("financing_date");
        List<QccFinancingInfo> qccFinancingInfos = qccFinancingInfoService.getBaseMapper().selectList(queryWrapper3);

        CompanyVo vo = new CompanyVo();
        vo.setCompany(company);
        vo.setQccBusinessInfos(qccBusinessInfos);
        vo.setQccCompanyInfo(qccCompanyInfo);
        vo.setQccFinancingInfos(qccFinancingInfos);
        return vo;
    }
}
